 
module.exports = {
    get1: function(url, data = {}) {
      var parmes = {
        openid1: wx.getStorageSync('openid')
      };
      return new Promise(function (o, r) {
        wx.request({
          url: getApp().globalData.baseUrl + url,
          // url: url,
          data: {
            ...data,
            ...parmes
          },
          method: "GET",
          header: {
            'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
            'token': wx.getStorageSync('token')
          },
          success: function (e) {
            o(e.data);
            if (e.data.code == -1) {
              wx.switchTab({
                url: '/pages/usercenter/usercenter',
              })
            } else if (e.data.code == 0) {
              const err = e.data.msg ? e.data.msg : '出错误了';
              wx.showToast({
                title: err,
                icon: 'none'
              })
            }
          },
          fail: function (e) {
            wx.showToast({
              title: '网络连接异常',
              icon: 'none'
            })
          },
          complete: function () {
            wx.hideLoading()
          }
        });
      });
    },
    post1: function(url, data = {}) {
      var parmes = {
        openid1: wx.getStorageSync('openid')
      };
      return new Promise(function (o, r) {
        wx.request({
          url: getApp().globalData.baseUrl + url,
          data: {
            ...data,
            ...parmes
          },
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
            'token': wx.getStorageSync('token')
          },
          success: function (e) {
            o(e.data);
            if (e.data.code == -1) {
              o(e.data);
              wx.switchTab({
                url: '/pages/usercenter/usercenter',
              })
            } else if (e.data.code == 0) {
              const err = e.data.msg ? e.data.msg : '出错误了';
              wx.showToast({
                title: err,
                icon: 'none'
              })
            }
          },
          fail: function (e) {
            wx.showToast({
              title: '网络连接异常',
              icon: 'none'
            })
          },
          complete: function () {
            wx.hideLoading()
          }
        });
      });
    }, 
    postJson: function(url, data = {}) {
      var parmes = {
        openid1: wx.getStorageSync('openid')
      };
      return new Promise(function (o, r) {
        wx.request({
          url: getApp().globalData.baseUrl + url,
          data: {
            ...data,
            ...parmes
          },
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
            'token': wx.getStorageSync('token')
          },
          success: function (e) {
            o(e.data);
            if (e.data.code == -1) {
              o(e.data);
              wx.switchTab({
                url: '/pages/usercenter/usercenter',
              })
            } else if (e.data.code == 0) {
              const err = e.data.msg ? e.data.msg : '出错误了';
              wx.showToast({
                title: err,
                icon: 'none'
              })
            }
          },
          fail: function (e) {
            wx.showToast({
              title: '网络连接异常',
              icon: 'none'
            })
          },
          complete: function () {
            wx.hideLoading()
          }
        });
      });
    }, 
};